<?php 
class Input {

    static public function getInstance(){
        return new self();
    }
    
	private function _fetch_from_array(&$array, $index = '' ,$default = null)
	{
		if ( ! isset($array[$index]))
		{
			return $default;
		}

		return $array[$index];
	}


	public function get($index = '', $default = null)
	{
		return $this->_fetch_from_array($_GET, $index, $default);
	}


	public function post($index = '', $default = null)
	{
		return $this->_fetch_from_array($_POST, $index, $default);
	}


	public function request($index = '', $default = null)
	{
		if ( ! isset($_POST[$index]))
		{
			return $this->get($index, $default);
		}
		else
		{
			return $this->post($index, $default);
		}
	}


	public function isRequest($method) {
		$request_method = $_SERVER['REQUEST_METHOD'];
		if($request_method==$method){
			return true;
		}
		return false;
	}

	public function isPost() {
		$request_method = $_SERVER['REQUEST_METHOD'];
		if($request_method=='POST'){
			return true;
		}
		return false;
	}

	public function isGet() {
		$request_method = $_SERVER['REQUEST_METHOD'];
		if($request_method=='GET'){
			return true;
		}
		return false;
	}

    public function isAjax() {
        return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
    }

	public function cookie($index = '', $default='')
	{
		return $this->_fetch_from_array($_COOKIE, $index,$default);
	}


	public function server($index = '', $default='')
	{
		return $this->_fetch_from_array($_SERVER, $index,$default);
	}

}